using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using System;
using UnityEngine.UI;

namespace MainScenePanelRoot
{
    public class MainPanel : PanelRoot
    {
        private Button ButtonPanel;
        private Button ButtonLogin;
        private Button ButtonSetting;
        private Button ButtonSinglePlayer;
        private Button ButtonMultiPlayer;
        private GameObject DivStart;
        private GameObject TextGameStart;
        private bool isDivStartUp;
        private bool isDivLeftLeft;


        public MainPanel() : base(null)
        {
            gameobject = GameTool.Instance.GetGameObjectFromCanvas(GetType().Name);
            //children.Add(new PanelLogin(this));
            //children.Add(new PanelOnlineAlert(this));
            children.Add(new PanelSetting(this));
            isDivStartUp = false;
            isDivLeftLeft = false;
        }
        protected override void Oninit()
        {
            base.Oninit();
            OnResume();
            TextGameStart = GameTool.Instance.GetGameObjectFromChildren(gameobject, "Start_text");
            //ButtonLogin = GameTool.Instance.GetComponentFromChild<Button>(gameobject, "ButtonLogin");
            if(gameobject!=null)
            Debug.Log("fuck");
            ButtonSetting = GameTool.Instance.GetComponentFromChild<Button>(gameobject, "ButtonSetting");
            ButtonPanel = gameobject.GetComponent<Button>();
            ButtonSinglePlayer = GameTool.Instance.GetComponentFromChild<Button>(gameobject, "Single");
            ButtonMultiPlayer = GameTool.Instance.GetComponentFromChild<Button>(gameobject, "Multy");
            DivStart = GameTool.Instance.GetGameObjectFromChildren(gameobject, "Start");
            //DivLeft = GameTool.Instance.GetGameObjectFromChildren(gameobject, "DivLeft");
            DivStart.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, -125);
            ButtonPanel.onClick.AddListener(() =>
            {
                TextGameStart.SetActive(!TextGameStart.activeSelf);
                if (!isDivStartUp)
                {
                    Debug.Log(1);
                    isDivStartUp = !isDivStartUp;
                    DivStart.SetActive(true);
                    DivStart.GetComponent<RectTransform>().DOAnchorPosY(125, 0.3f);
                    Debug.Log(1);

                }
                else
                {
                    Debug.Log(2);
                    isDivStartUp = !isDivStartUp;
                    DivStart.SetActive(true);
                    DivStart.GetComponent<RectTransform>().DOAnchorPosY(-125, 0.3f);
                }

                
            });
            ButtonSetting.onClick.AddListener(() =>
            {
                EnterPanel(typeof(PanelSetting));
            });
            /*ButtonSinglePlayer.onClick.AddListener(() =>
            {
                SceneModelCommand.Instance.LoadScene(SceneName.MiddleScene);
            });
            ButtonMultiPlayer.onClick.AddListener(() =>
            {
                EnterPanel(typeof(PanelOnlineAlert));
            });
            ButtonLogin.onClick.AddListener(() =>
            {
                EnterPanel(typeof(PanelLogin));
            });*/
        }
        protected override void OnEnter()
        {
            base.OnEnter();
            if (!isDivStartUp)
            {
                TextGameStart.SetActive(true);
                isDivLeftLeft = false;
            }
        }
        protected override void EnterPanel(Type type)
        {
            base.EnterPanel(type);
            TextGameStart.SetActive(false);
            isDivLeftLeft = true;
        }
    }
}

